/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import java.io.IOException;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

/**
 *
 * @author Administrator
 */
public class AboutCanvas extends Canvas {

    Display display;
    TheBirdMIDlet midlet;
    private Image imgBackground;
    private Image imgBack;
    private Image imgAbout;
    private ButtonImage btnBack;
//--- gesture ---    
    private int x;
    private int y;
//--- end-gesture ---

    public AboutCanvas(TheBirdMIDlet midlet, Display display) {
        setFullScreenMode(true);
        this.midlet = midlet;
        this.display = display;
        try {
            imgBack = Image.createImage("/btnBacktoLeft.png");
            imgAbout = Image.createImage("/btnAboutOn320.png");
        } catch (IOException ex) {
            ex.printStackTrace();
        }

        int xyArea[] = new int[4];
        int hBack = 0;//getWidth() - imgMineIdOff.getWidth();
        int wBack = getHeight() - imgBack.getHeight();

        xyArea[0] = wBack; //x1
        xyArea[1] = wBack + imgBack.getWidth(); //x2
        xyArea[2] = hBack; //y1
        xyArea[3] = hBack + imgBack.getHeight(); //y2
        btnBack = new ButtonImage("backEn", imgBack, imgBack,
                imgBack, hBack,
                wBack, xyArea, Graphics.TOP | Graphics.LEFT);
    }

    protected void paint(Graphics g) {
        g.setColor(0xFFFFFF);
        g.fillRect(0, 0, getWidth(), getHeight());
        g.setColor(0x0000FF);
        
        g.drawImage(imgAbout, 20, 20,
                Graphics.TOP | Graphics.LEFT);
        String info[] = new String[42];
        info[0] = "App Name : Ninja Run";
        info[1] = "Developer : Fathurrahman";        
        info[2] = "Version : 1.0";
        //int index = 0;
        g.setFont(MenuCanvas.SMALL_BOLD_FONT);
        int yInfo = 70;
        for (int i = 0; i < 3; i++) {
            g.drawString(info[i], 10, yInfo, Graphics.TOP | Graphics.LEFT);
            yInfo = yInfo + 20;
        }

        btnBack.paint(g);
    }

    protected void keyPressed(int keyCode) {
        
        if (keyCode == -6) {
            midlet.showMenuCanvas();
        }
        repaint();
    }

    protected void pointerPressed(int x, int y) {
        this.x = x;
        this.y = y;

        if (x > btnBack.xImage
                && x < (btnBack.xImage + btnBack.imageWidth)
                && y > btnBack.yImage
                && y < (btnBack.yImage + btnBack.imageHeight)) {
            btnBack.pointerPressed(x, y);
        }

        repaint();
    }

    protected void pointerReleased(int x, int y) {
        this.x = x;
        this.y = y;

        if (x > btnBack.xImage
                && x < (btnBack.xImage + btnBack.imageWidth)
                && y > btnBack.yImage
                && y < (btnBack.yImage + btnBack.imageHeight)) {
            btnBack.pointerReleased(x, y);
            midlet.showMenuCanvas();
        }
        repaint();
        //scroll
    }
}
